package com.fieldchain.ex.fa100.custom.dialog;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.fieldchain.ex.fa100.R;
import com.fieldchain.ex.fa100.inter.IntegerCallBack;
import com.fieldchain.ex.fa100.utils.share.ShareManager;

/**
 * Created by 123 on 2018/6/8.
 */

public class C2CDialog extends BaseDialog {
    private LinearLayout linTradpwd;
    private CheckBox cb1;
    private ImageView iv1;
    private LinearLayout linShiming;
    private CheckBox cb2;
    private ImageView iv2;
    private LinearLayout linBindbank;
    private CheckBox cb3;
    private ImageView iv3;
    private TextView tvSure;
    private int tag1, tag2, tag3;
    private IntegerCallBack callBack;

    public C2CDialog(Context context, IntegerCallBack callBack) {
        super(context);
        this.callBack = callBack;
    }

    @Override
    public int setLayout() {
        return R.layout.dialog_c2c;
    }

    @Override
    public void findView() {
        linTradpwd = findViewById(R.id.lin_tradpwd);
        cb1 = findViewById(R.id.cb1);
        iv1 = findViewById(R.id.iv1);
        linShiming = findViewById(R.id.lin_shiming);
        cb2 = findViewById(R.id.cb2);
        iv2 = findViewById(R.id.iv2);
        linBindbank = findViewById(R.id.lin_bindbank);
        cb3 = findViewById(R.id.cb3);
        iv3 = findViewById(R.id.iv3);
        tvSure = findViewById(R.id.tv_sure);

        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.dimAmount = 0f;
        getWindow().setAttributes(lp);
    }

    @Override
    public void setValue() {
        Log.e("hhhhhhhhhhh",ShareManager.getInstance().getHeight()+"");
        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }

    public void setTags(final int tags1, final int tags2, final int tags3) {
        this.tag1 = tags1;
        this.tag2 = tags2;
        this.tag3 = tags3;
        setTag(tags1, cb1, iv1);
        setTag(tags2, cb2, iv2);
        setTag(tags3, cb3, iv3);

        if (tags1 == 0) {
            linTradpwd.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    callBack.index(1);
                }
            });
        }
        if (tags2 == 0) {
            linShiming.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    callBack.index(2);
                }
            });
        }
        if (tags3 == 0) {
            linBindbank.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    callBack.index(3);
                }
            });
        }

    }

    private void setTag(int tag, CheckBox cb, ImageView iv) {
        if (tag == 1) {
            cb.setChecked(true);
            iv.setVisibility(View.GONE);
        } else {
            cb.setChecked(false);
            iv.setVisibility(View.VISIBLE);
        }


    }

}
